<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
	<link rel="stylesheet" href="../../css/normalize.css"/>
	<link rel="stylesheet" href="../../css/fa.css"/>
	<link rel="stylesheet" href="../../css/icon.css"/>
	<link rel="stylesheet" href="../../css/ares_animate.min.css"/>
	<link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
	<link rel="stylesheet" href="../../css/ares_reboot.css"/>
	<link rel="stylesheet" href="../../css/app.min.css"/>
	<link rel="stylesheet" href="../../css/iframe.css"/>
</head>
<body>
<form class="layui-form layui-row">
	<div class="layui-col-xs12 layui-col-md6">
		<div class="layui-form-item">
			<label class="layui-form-label">旧密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请输入旧密码" lay-verify="required" name="oldPwd" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请输入新密码" minlength="6" maxlength="15" lay-verify="required|rangeLength" id="new-pwd" name="newPwd" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input type="password" value="" placeholder="请确认密码" lay-verify="required|confirmPwd" name="confirmPwd" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="changePwd">立即修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script type="text/javascript">
	layui.use(['form', 'authServices','utils'], function (form,authServices,utils) {

		/**
		 * @author: ares
		 * @date: 2020/2/17 18:28
		 * @description: 自定义校验
		 */
		form.verify({
			confirmPwd : function(value, item){
				if(!new RegExp($("#new-pwd").val()).test(value)){
					return "两次输入密码不一致，请重新输入！";
				}
			}
		})

		/**
		 * @author: ares
		 * @date: 2020/2/17 18:28
		 * @description: 模拟修改密码
		 */
		form.on("submit(changePwd)", function (data) {
			var field = data.field,
				oldPwd = field.oldPwd,
				newPwd = field.newPwd;
				index = utils.layerLoadingMsg('提交中，请稍候');
            authServices.modifyPwd(oldPwd, newPwd).then(function (res) {
				utils.layer.close(index);
                utils.msgSuccess(res.message);
                authServices.logout();
			}).catch(function (err) {
                utils.layer.close(index);
            })
			return false;
		})
	})
</script>
</body>
</html>